import { getHoverMsg, getEnum } from '@/api/productApi/file'
import { Completion } from '@/utils/hovePerty'
import { returnData } from '@/utils/dataType'
import Vue from 'vue'
const state = {
	pulicCheckNum: { // 公募步骤未复核数量
		baseInfo: { num: 0 },
		dateInfo: { num: 0 },
		organInfo: { num: 0 },
		rateInfo: { num: 0 },
		investInfo: { num: 0 },
		fundMange: { num: 0 },
		fileInfo: { num: 0 }
	},
	pucliktTotalData: { // 公募数据
		fundRaiseType: '1',
		fundSysCode: '',
		productFundApply: {

		}
	},
	pulicAttribute: [], // 公募变更属性列表

	specialCheckNum: { // 专户步骤未复核数量
		baseInfo: { num: 0 },
		dateInfo: { num: 0 },
		organInfo: { num: 0 },
		rateInfo: { num: 0 },
		investInfo: { num: 0 },
		riskInfo: { num: 0 },
		consignerInfo: { num: 0 },
		fundMange: { num: 0 },
		fileInfo: { num: 0 }
	},
	specialtTotalData: { // 专户数据
		fundRaiseType: '2',
		fundSysCode: '',
		productFundApply: {

		}
	},
	specialAttribute: [], // 专户变更属性列表

	// 公募与专户的基础数据
	publicBaseInfo: {},
	specialBaseInfo: {},

	// 全局hover
	hoverPerty: {},

	// 全局下属基金
	subordinateFund: []
}

const mutations = {
	RESET_NUM: (state) => {
		state.pucliktTotalData = {
			fundRaiseType: '1',
			fundSysCode: '',
			productFundApply: {

			}
		}
		state.pulicAttribute = []
		for (const i in state.pulicCheckNum) {
			Vue.set(state.pulicCheckNum[i], 'num', 0)
		}
		/** ***********************/
		state.specialtTotalData = {
			fundRaiseType: '2',
			fundSysCode: '',
			productFundApply: {

			}
		}
		state.specialAttribute = []
		for (const i in state.specialCheckNum) {
			Vue.set(state.specialCheckNum[i], 'num', 0)
		}
	},

	SET_HOVER: (state, obj) => {
		state.hoverPerty = obj
	},

	SET_FUND: (state, list) => {
		state.subordinateFund = list
	}
}

const actions = {

	resetNum({ commit }) {
		commit('RESET_NUM')
	},

	async setHover({ commit }) {
		await getHoverMsg().then(res => {
			if (res.msgCode === 'Y') {
				if (!res.data.body) {
					res.data.body = {}
				}
				const keys = Object.keys(res.data.body)
				if (keys.length) {
					for (const i in res.data.body) {
						if (i !== 'hoverInfoId') {
							if (!res.data.body[i] || returnData(res.data.body[i]) !== 'Object') {
								res.data.body[i] = {}
							}
						}
					}
				}
				const obj = Completion(res.data.body)
				commit('SET_HOVER', obj)
			}
		})
	},

	getFundEumn({ commit }) { // 获取下属基金类型
		getEnum(['subFundType']).then(res => {
			if (res.msgCode === 'Y') {
				commit('SET_FUND', res.data.body.subFundType)
			}
		})
	}
}
export default {
	namespaced: true,
	state,
	mutations,
	actions
}
